Add Maybe-returning tryGetOrCreateAsMaybe to Hashtable and FlatHashtable - #12335
Closed
dougqh wants to merge 3 commits into
Closed
Add Maybe-returning tryGetOrCreateAsMaybe to Hashtable and FlatHashtable#12335dougqh wants to merge 3 commits into
dougqh wants to merge 3 commits into
Conversation
Maybe/MaybeTest/EscapeShapeBenchmark/MaybeUsagePatternsBenchmark, copied verbatim from the merge-queued PR #12328, so this branch (stacked on #12101) can add Maybe-returning Hashtable/FlatHashtable methods without waiting on the queue. Drop this commit's contents in favor of master's copy once this branch rebases past #12328 landing.
Additive siblings to tryGetOrCreate on Hashtable.D1/D2 and FlatHashtable.D1/D2, wrapping the existing @Nullable-returning method in a Maybe rather than changing its signature. Each delegates to the existing tryGetOrCreate as its sole Maybe#of call site, keeping the allocation-free shape Maybe's class javadoc requires. Validates Maybe against a real caller: the client-side-stats PR (#12312) stacked on top of this one converts CardinalityLimitReporter to tryGetOrCreateAsMaybe(...).update(...).
This comment has been minimized.
This comment has been minimized.
… to tryGetOrCreateOrNull Maybe becomes the primary get-or-create contract on Hashtable.D1/D2 and FlatHashtable.D1/D2; the raw nullable form survives as an escape hatch under a less-prominent name. Breaking change is affordable now: CardinalityLimitReporter is the only production caller and is updated to the renamed OrNull method here (the fused Maybe-based conversion lands separately in #12312).
Contributor
🟢 Java Benchmark SLOs — All performance SLOs passed
PR vs. master results
Commit: Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Maybe<T>-wrappedtryGetOrCreatethe primary get-or-create API onHashtable.D1/D2andFlatHashtable.D1/D2, replacing the old@Nullable-returning method under that name.@Nullable-returningtryGetOrCreateis renamed totryGetOrCreateOrNull, kept as a low-level escape hatch for callers whereMaybe's allocation-free contract doesn't fit.tryGetOrCreatedelegates to it as the soleMaybe#ofcall site, preserving the allocation-free shapeMaybe's class javadoc requires.CardinalityLimitReporter(updated here to calltryGetOrCreateOrNull) is the only real production caller, and theHashtable.D1/D2tryGetOrUpdateoverloads are updated to calltryGetOrCreateOrNullinternally.Maybe/MaybeTest/benchmark files forward from Introduce Maybe<T> an allocation free return value for fallible operations #12328 in a separate temporary commit until Introduce Maybe<T> an allocation free return value for fallible operations #12328 merges to master, at which point this branch will rebase to drop that commit.CardinalityLimitReporterto usetryGetOrCreate(...).update(...)in place oftryGetOrUpdate, with a JMH check that it stays allocation-free.Test plan
./gradlew :internal-api:compileJava :internal-api:compileTestJava :dd-trace-core:compileTestJavasucceedsHashtableD1Test,HashtableD2Test,FlatHashtableD1Test,FlatHashtableD2Testcover present/absent-at-capacity behavior of bothtryGetOrCreate(Maybe) andtryGetOrCreateOrNull(nullable)./gradlew :internal-api:test(targeted Hashtable/FlatHashtable/Maybe tests) passes./gradlew spotlessApplyrun, no outstanding formatting diffsCardinalityLimitReportercaller in Use the unified Hashtable API in client-side stats #12312 (pending that PR's rebase onto this one)🤖 Generated with Claude Code